package cc.sheji.config;

import cn.dev33.satoken.stp.StpInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import java.util.ArrayList;
import java.util.List;

@Component    // 保证此类被SpringBoot扫描，完成sa-token的自定义权限验证扩展
public class StpInterfaceImpl implements StpInterface {
//    @Autowired
//    private UserDao userDao;
//    @Autowired
//    private RoleMapper roleMapper;
//    @Autowired
//    private User_RoleMapper user_roleMapper;
    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginKey) {
        // 查出当前用户的权限信息
        List<String> list = new ArrayList<String>();
        list.add("111");
//        List<Permission> permissions = userDao.findPermissionByUserName(loginId.toString());
//        permissions.forEach(l -> {
//            list.add(l.getPermTag());
//        });
        return list;
    }
    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginKey) {
        // 查出当前用户的角色信息
        List<String> list = new ArrayList<String>();
        list.add("111");
//        int id = userDao.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername, loginId.toString())).getId();
//        List<User_Role> user_roles = user_roleMapper.selectList(Wrappers.<User_Role>lambdaQuery().eq(User_Role::getUid, id));
//        user_roles.forEach( l -> {
//            int rid = l.getRid();
//            Role role = roleMapper.selectOne(Wrappers.<Role>lambdaQuery().eq(Role::getId, rid));
//            list.add(role.getRoleName());
//        });
        return list;
    }
}